package huajiu.com.dao;

import huajiu.com.base.BaseDao;
import huajiu.com.domain.DoctorSolution;

import java.util.List;

import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional
public class DoctorSolutionDao {
	@Autowired
	private BaseDao<DoctorSolution> baseDao;
	
	
	public void save(DoctorSolution doctorSolution){
		baseDao.save(doctorSolution);
	}
	
	public void delete(DoctorSolution doctorSolution){
		baseDao.delete(doctorSolution);
	}
	
	public void update(DoctorSolution doctorSolution){
		baseDao.save(doctorSolution);
	}
	
	
	public DoctorSolution selectByDoctor(String doctor){
		
		String queryString = " SELECT t.* FROM doctor_solution t where t.doctor=:doctor ";
		List<DoctorSolution> doctorSolution = baseDao.getCurrentSession().createSQLQuery(queryString).addEntity(DoctorSolution.class).setParameter("doctor", doctor).list();
		if(doctorSolution.size()==0){
			DoctorSolution doctorSolutiona = new DoctorSolution();
			doctorSolutiona.setUuid("no");
			return doctorSolutiona ;
		}else {
			return doctorSolution.get(0);
		}
	}
	
	public List<DoctorSolution> getDoctorSolutions(){
		String queryString = "select t.*,t.create_time as createTime from doctor_solution t where state='0'";
		List<DoctorSolution> solutions = baseDao.getCurrentSession().createSQLQuery(queryString).addEntity(DoctorSolution.class).list();
		return solutions;
	}
}
